use stencil_util::{FieldName, TypeName};

use super::common::{TypeFamily, Typedef};
use crate::{field::FieldOp, FieldLocator, FieldShape, SequenceLenDesc};

/// Records are like dynamic structs.
///
/// They can have fields that are of dynamic lengths.
#[derive(Clone, Debug)]
pub struct RecordBufTd {
    name: TypeName,

    /// Minimum buffer size.
    min_buf_size: u64,
}

impl Typedef for RecordBufTd {
    fn name(&self) -> &TypeName {
        &self.name
    }

    fn family(&self) -> TypeFamily {
        TypeFamily::Buf
    }
}

#[derive(Clone, Debug)]
pub struct RecordBufTdField {
    name: FieldName,

    /// If this is a dynamic shape, then `len` must be set.
    shape: FieldShape,

    /// Description of the field in the struct.
    locator: FieldLocator,

    /// Describes the length of the sequence, if the shape is a sequence.
    len: Option<SequenceLenDesc>,

    /// Operations we want to expose for this field.
    ops: Vec<FieldOp>,
}
